<?php

namespace app\controllers\h5\uni;

use app\controllers\h5\base\H5Controller;
use app\models\ExpressShowList;
use app\models\SetExpressApi;
use app\models\SetUserUp;
use app\models\system\SetAd;
use app\models\system\SetApp;
use app\models\system\SetFlow;
use app\models\system\SetSwiper;
use app\models\user\UserAccount;

class ExpressController extends H5Controller
{
    public function actionIndex()
    {
        // 轮播图
        $image = SetSwiper::find()
            ->where(['category_id' => 11])
            ->andWhere(['status' => 1])
            ->orderBy(['sort' => SORT_ASC, 'id' => SORT_DESC])
            ->with(['image'])
            ->asArray()
            ->all();

        // 快递列表
        $list = ExpressShowList::find()
            ->orderBy(['sort' => SORT_ASC, 'id' => SORT_ASC])
            ->with(['image'])
            ->asArray()
            ->all();



        return $this->successEncode([
            'image' => $image,
            'list' => $list,
            'wx' => SetFlow::getLastOne()->wx == 1,
        ]);
    }

    // 广告位
    public function actionAd()
    {
        $list = SetAd::find()
            ->where(['category_id' => 1])
            ->andWhere(['status' => 1])
            ->orderBy(['sort' => SORT_ASC, 'id' => SORT_DESC])
            ->with(['image'])
            ->asArray()
            ->all();

        return $this->successEncode([
            'list' => $list,
        ]);
    }

    // 优惠券列表
    public function actionGetTicket()
    {
        $set = SetUserUp::getLastOne();
        $account = UserAccount::findOne(['user_id' => $this->user->id]);

        return $this->successEncode([
            'set' => [
                'use' => $set->card_use,
                'amount' => (float)$set->card_amount,
                'num' => $set->card_num,
            ],
            'ticket' => (float)$account->ticket,
        ]);
    }

    public function actionSet()
    {
        $ratio = (float)SetExpressApi::getLastOne()->ratio;

        return $this->successEncode([
            'ratio' => $ratio,
            'wx' => SetFlow::getLastOne()->wx,
        ]);
    }
}